// 给定数组 ['1a','2b','9c','5a'] ，输出出现次数最多的字母前数字之和 （此例最多字母为a，和为6）

const getKey = arr => {
  const map = {}
  let key = ''
  let max = 0
  arr.forEach(item => {
    const str = item.slice(-1)
    if (!map[str]) map[str] = 0
    map[str]++
    if (max < map[str]) {
      max = map[str]
      key = str
    }
  })
  return key
}

const getSum = (arr, key) => {
  const keyArr = arr.filter(item => item.includes(key))
  return keyArr.map(item => item.slice(0, -1)).reduce((prev, next) => prev + parseInt(next), 0)
}

const arr = ['1a', '2b', '9c', '5a']

const key = getKey(arr)

const sum = getSum(arr, key)

console.log(sum)
